using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using UnityEngine.Serialization;

namespace MyTanks
{
    public class MyTanksAuthoring : MonoBehaviour
    {
        [Range(1, 50)] public int tankCount;
        [Range(.1f, 50f)] public float tankMoveSpeed = 5f;

        [Range(0.02f, 2)] public float shootInterval;

        [Range(0.5f, 40f)] public float shellFlySpeed = 5f;


        [Range(0f, 2f)] public float gravityRatio = .3f;

        public GameObject tankPrefabA;
        public GameObject tankPrefabB;

        public GameObject shellPrefab;
        public GameObject shellExplosionPrefab;

        class Baker : Baker<MyTanksAuthoring>
        {
            public override void Bake(MyTanksAuthoring authoring)
            {
                var entity = GetEntity(TransformUsageFlags.None);

                AddComponent(entity, new MyTanksConfig()
                {
                    tankCount = authoring.tankCount,
                    shootInterval = authoring.shootInterval,
                    shellFlySpeed = authoring.shellFlySpeed,
                    tankMoveSpeed = authoring.tankMoveSpeed,
                    gravityRatio = authoring.gravityRatio,
                    tankPrefab_A = GetEntity(authoring.tankPrefabA, TransformUsageFlags.Dynamic),
                    tankPrefab_B = GetEntity(authoring.tankPrefabB, TransformUsageFlags.Dynamic),

                    shellPrefab = GetEntity(authoring.shellPrefab, TransformUsageFlags.Dynamic),
                    shellExplosionPrefab = GetEntity(authoring.shellExplosionPrefab, TransformUsageFlags.Dynamic)
                });
            }
        }
    }

    public struct MyTanksConfig : IComponentData
    {
        public int tankCount;
        public float shootInterval;
        public float shellFlySpeed;
        public float tankMoveSpeed;
        public float gravityRatio;
        public Entity tankPrefab_A;
        public Entity tankPrefab_B;

        public Entity shellPrefab;
        public Entity shellExplosionPrefab;
    }
}